//
//  EveryDayTaskVC.m
//  NormalFramework
//
//  Created by beisheng03 on 2018/3/16.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "EveryDayTaskVC.h"
#import "EveryDayTaskCell.h"
@interface EveryDayTaskVC ()
@property (nonatomic, strong) NSMutableArray<NSObject *> *dataModels;

/** <#note#> */
@property (nonatomic, strong) UIView *headerView;
@end

@implementation EveryDayTaskVC

- (UIView *)headerView{
    
    if (!_headerView) {
        _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, 52)];
        _headerView.backgroundColor = viewBgGrey;
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = MYFONT(16);
        titleLabel.text = @"新手任务";
        titleLabel.frame = _headerView.bounds;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [_headerView addSubview:titleLabel];
    }
    
    
    return _headerView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"每日任务";
    
//    self.automaticallyAdjustsScrollViewInsets = NO;
//
//    if (@available(iOS 11.0, *)) {
//
//
//        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//
//    }
//    self.tableView.rowHeight = 90;
//
//    CGFloat top = IPhoneX ? 88 : 64;
//    self.tableView.contentInset = UIEdgeInsetsMake(top + 135, 0, IPhoneX ? 34 : 0, 0);
    
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([EveryDayTaskCell class]) bundle:nil] forCellReuseIdentifier:[EveryDayTaskCell identifierStr]];
    
    
    MJWeakSelf
    self.tableView.mj_header = [XMGRefreshHeader headerWithRefreshingBlock:^{
        
        
        [weakSelf loadData];
        
    }];
    
        [self.tableView.mj_header beginRefreshing];

    
    self.tableView.tableFooterView = [[UIView alloc]init];
    
    
    
}





- (void)loadData{

    
    NSMutableDictionary *parmars = [NSMutableDictionary dictionary];
    
    
    MJWeakSelf;
    [[NetworkTools shareNetworkTools]sendRequestWithHttpMethod:POST_METHOD URLPath:@"index.php/Api/Dbindex/get_more" parameters:parmars completionHandler:^(id responseObject, NSError *error) {
        
        if (!error) {
            
            //            NSLog(@"%@",[responseObject mj_JSONString]);
            
            
            
            
            self.dataModels = [NSObject mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]];
            
            
            

            [weakSelf.tableView.mj_header endRefreshing];
            
            [weakSelf.tableView reloadData];
            
        } else {
            
            [weakSelf.tableView.mj_header endRefreshing];
            
            [SVProgressHUD showErrorWithStatus:error.domain];
            
        }
        
        
        
    }];
    
    
    
}






#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
    
    if (self.dataModels == nil) {
        return 0;
    }
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 4;
    } else {
        return 2;
    }
    if (self.dataModels == nil) {
        return 0;
    }
    return self.dataModels.count;
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    EveryDayTaskCell *cell = [tableView dequeueReusableCellWithIdentifier:[EveryDayTaskCell identifierStr] ];
    
    
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    return 72;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    if (section == 0) {
        return 0;
    } else {
        return 52;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0;
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    
    return [[UIView alloc]init];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        
        return [[UIView alloc]init];
        
    } else {
    
        return self.headerView;
    }
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
